package com.example.login_demo.slice;

import com.example.easyhttp.EasyCallBack;
import com.example.easyhttp.LogUtils;
import com.example.login_demo.ResourceTable;
import com.example.login_demo.base.BaseAbilitySlice;
import com.example.login_demo.base.UserInfoDataBean;
import com.example.login_demo.common.http.EasyHttpUtils;
import com.example.login_demo.data.DataManager;

import ohos.agp.components.*;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.util.HashMap;
import java.util.Map;

/**
 * 登录页面
 */
public class UserLoginAbilitySlice extends BaseAbilitySlice implements Component.ClickedListener {
    private Component mIvBack;
    private Button mBtLogin;
    private TextField mTfphone;
    private TextField mTfPassword;

    static final HiLogLabel label=new HiLogLabel(HiLog.LOG_APP,0x00201,"MY_TAG");
    private DependentLayout mDlBack;

    @Override
    public int getLayout() {
        return ResourceTable.Layout_login_layout;
    }

    @Override
    public void initView() {
        DataManager.getInstance().init(mContext);


        mIvBack = findComponentById(ResourceTable.Id_iv_back);
        mBtLogin = (Button) findComponentById(ResourceTable.Id_bt_login);
        mTfphone = (TextField) findComponentById(ResourceTable.Id_tf_phone);
        mTfPassword = (TextField) findComponentById(ResourceTable.Id_tf_password);
         mDlBack = (DependentLayout) findComponentById(ResourceTable.Id_dl_back);

    }

    @Override
    public void initListener() {
        mIvBack.setClickedListener(this);
        mBtLogin.setClickedListener(this);
        mTfphone.setClickedListener(this);
        mTfPassword.setClickedListener(this);
        mDlBack.setClickedListener(this);

    }

    @Override
    public void onClick(Component component) {
        switch (component.getId())
        {
            case ResourceTable.Id_dl_back:
                LogUtils.e("","返回按钮");

                onBackPressed();
                break;

            case ResourceTable.Id_bt_login:
//                // 手机号
//                String mPhone= mTfphone.getText();
//                // 密码
//                String mPassword= mTfPassword.getText();
//
//                if(mPhone==null||"".equals(mPhone))
//                {
//                    LogUtils.e("","手机号不能为空");
//                    return;
//                }
//
//                if (!StringUtils.isMobileNO( mPhone )) {
//                    LogUtils.e("","手机号码格式错误，请重新输入(ฅ´ω`ฅ)");
//                    return;
//                }
//                if(mPassword==null||"".equals(mPassword))
//                {
//                    LogUtils.e("","密码不能为空");
//                    return;
//                }
//
//                if (mPassword.length() < 6) {
//                    LogUtils.e("","\\\"密码\\\"必须是6位或以上任意字符");
//                    return;
//                }
//                if (mPassword.length() > 18) {
//                    LogUtils.e("","\\\"密码\\\"必须是18位以内任意字符");
//                    return;
//                }
                String black_box = "eyJvcyI6ImFuZHJvaWQiLCJ2ZXJzaW9uIjoiMy41LjMiLCJwcm9maWxlX3RpbWUiOjE2MywiaW50ZXJ2YWxfdGltZSI6MTY4MjQsInBhY2thZ2VzIjoiY29tLmhvb2xhaS5tb2VnbyIsImNzaWQiOiIxNTkyMzEzODc3NzQyNDQxNzQ4IiwidG9rZW5faWQiOiJKVElCQVlaclpcL1RSdmY5R1VyYTVwaHI5VEZCWW5HanJucmp0Y1dcLzdoRmxXRWdod2RjVWJacTJLTnN3Mnd4bFVtTUlHVlwvMk1XUWpTdnJRUUFldWJKdz09In0%3D";
                String phone = "15501149225";
                String passwd = "111111";
                String url = "https://t-app.moego.net/v3/member/user/login";

                Map<String, String> paramsMap = new HashMap<>();
                paramsMap.put("black_box", black_box);
                paramsMap.put("phone", phone);
                paramsMap.put("passwd", passwd);

                paramsMap.put(passwd, passwd);

                EasyHttpUtils.getInstance().post(url, paramsMap, new EasyCallBack.CallBackObject<UserInfoDataBean>() {
                    @Override
                    public void onFailure(int code, String errorMessage) {
                        //http访问出错了，注意此部分内容在主线程中工作，可以更新UI等操作，但请不要执行阻塞操作。
//                        mIdText.setText("post访问出错：" + errorMessage);
                        LogUtils.e("","post访问出错：" + errorMessage);
                    }

                    @Override
                    public void onResponse(UserInfoDataBean response) {
//                        mIdText.setText("post访问成功：" + response.toString());
                        LogUtils.e("","post访问成功：" + response.toString());

                    }

                });

                break;
            case ResourceTable.Id_tf_phone:


                break;
            case ResourceTable.Id_tf_password:


                break;
        }
    }
}
